using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using EntLibEC.Info.Sale;
using EntLibEC.Cmn;

namespace EntLibEC.Dac.Sale
{
	/// <summary>
	/// Summary description for SODac.
	/// </summary>
	public class SODac
	{
		public SODac()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		
		public int InsertMaster(SOInfo oParam)
		{
			string sql = @"INSERT INTO Ent_SO_Master
                            (
                            SysNo, SOID, Status, CustomerSysNo, 
                            StockSysNo, OrderDate, DeliveryDate, SalesManSysNo, 
                            IsWholeSale, IsPremium, PremiumAmt, ShipTypeSysNo, 
                            ShipPrice, PayTypeSysNo, PayPrice, SOAmt, 
                            DiscountAmt, PointAmt, CashPay, PointPay, ReceiveAreaSysNo,
                            ReceiveContact, ReceiveName, ReceivePhone, ReceiveCellPhone, ReceiveAddress, 
                            ReceiveZip, AllocatedManSysNo, FreightUserSysNo, UpdateUserSysNo, 
                            UpdateTime, AuditUserSysNo, AuditTime, ManagerAuditUserSysNo, 
                            ManagerAuditTime, OutUserSysNo, OutTime, Memo, 
                            Note, InvoiceNote, IsVAT, IsPrintPackageCover, DeliveryMemo ,FinanceNote ,InvoiceNo ,
							IsLarge ,PositiveSOSysNo , IsMobilePhone, PromotionCodeSysNo
                            )
                            VALUES (
                            @SysNo, @SOID, @Status, @CustomerSysNo, 
                            @StockSysNo, @OrderDate, @DeliveryDate, @SalesManSysNo, 
                            @IsWholeSale, @IsPremium, @PremiumAmt, @ShipTypeSysNo, 
                            @ShipPrice, @PayTypeSysNo, @PayPrice, @SOAmt, 
                            @DiscountAmt, @PointAmt, @CashPay, @PointPay, @ReceiveAreaSysNo,
                            @ReceiveContact, @ReceiveName, @ReceivePhone, @ReceiveCellPhone, @ReceiveAddress, 
                            @ReceiveZip, @AllocatedManSysNo, @FreightUserSysNo, @UpdateUserSysNo, 
                            @UpdateTime, @AuditUserSysNo, @AuditTime, @ManagerAuditUserSysNo, 
                            @ManagerAuditTime, @OutUserSysNo, @OutTime, @Memo, 
                            @Note, @InvoiceNote, @IsVAT, @IsPrintPackageCover, @DeliveryMemo ,@FinanceNote ,@InvoiceNo ,
							@IsLarge ,@PositiveSOSysNo , @IsMobilePhone, @PromotionCodeSysNo
                            )";
			
			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
			SqlParameter paramSOID = new SqlParameter("@SOID", SqlDbType.NVarChar,20);
			SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4);
			SqlParameter paramCustomerSysNo = new SqlParameter("@CustomerSysNo", SqlDbType.Int,4);
			SqlParameter paramStockSysNo = new SqlParameter("@StockSysNo", SqlDbType.Int,4);
			SqlParameter paramOrderDate = new SqlParameter("@OrderDate", SqlDbType.DateTime);
			SqlParameter paramDeliveryDate = new SqlParameter("@DeliveryDate", SqlDbType.DateTime);
			SqlParameter paramSalesManSysNo = new SqlParameter("@SalesManSysNo", SqlDbType.Int,4);
			SqlParameter paramIsWholeSale = new SqlParameter("@IsWholeSale", SqlDbType.Int,4);
			SqlParameter paramIsPremium = new SqlParameter("@IsPremium", SqlDbType.Int,4);
			SqlParameter paramPremiumAmt = new SqlParameter("@PremiumAmt", SqlDbType.Decimal,9);
			SqlParameter paramShipTypeSysNo = new SqlParameter("@ShipTypeSysNo", SqlDbType.Int,4);
			SqlParameter paramShipPrice = new SqlParameter("@ShipPrice", SqlDbType.Decimal,9);
			SqlParameter paramPayTypeSysNo = new SqlParameter("@PayTypeSysNo", SqlDbType.Int,4);
			SqlParameter paramPayPrice = new SqlParameter("@PayPrice", SqlDbType.Decimal,9);
			SqlParameter paramSOAmt = new SqlParameter("@SOAmt", SqlDbType.Decimal,9);
			SqlParameter paramDiscountAmt = new SqlParameter("@DiscountAmt", SqlDbType.Decimal,9);
			SqlParameter paramPointAmt = new SqlParameter("@PointAmt", SqlDbType.Int,4);
			SqlParameter paramCashPay = new SqlParameter("@CashPay", SqlDbType.Decimal,9);
			SqlParameter paramPointPay = new SqlParameter("@PointPay", SqlDbType.Int,4);
			SqlParameter paramReceiveAreaSysNo = new SqlParameter("@ReceiveAreaSysNo", SqlDbType.Int,4);
			SqlParameter paramReceiveContact = new SqlParameter("@ReceiveContact", SqlDbType.NVarChar,20);
			SqlParameter paramReceiveName = new SqlParameter("@ReceiveName", SqlDbType.NVarChar,20);
			SqlParameter paramReceivePhone = new SqlParameter("@ReceivePhone", SqlDbType.NVarChar,100);
			SqlParameter paramReceiveCellPhone = new SqlParameter("@ReceiveCellPhone", SqlDbType.NVarChar,100);
			SqlParameter paramReceiveAddress = new SqlParameter("@ReceiveAddress", SqlDbType.NVarChar,200);
			SqlParameter paramReceiveZip = new SqlParameter("@ReceiveZip", SqlDbType.NVarChar,20);
			SqlParameter paramAllocatedManSysNo = new SqlParameter("@AllocatedManSysNo", SqlDbType.Int,4);
			SqlParameter paramFreightUserSysNo = new SqlParameter("@FreightUserSysNo", SqlDbType.Int,4);
			SqlParameter paramUpdateUserSysNo = new SqlParameter("@UpdateUserSysNo", SqlDbType.Int,4);
			SqlParameter paramUpdateTime = new SqlParameter("@UpdateTime", SqlDbType.DateTime);
			SqlParameter paramAuditUserSysNo = new SqlParameter("@AuditUserSysNo", SqlDbType.Int,4);
			SqlParameter paramAuditTime = new SqlParameter("@AuditTime", SqlDbType.DateTime);
			SqlParameter paramManagerAuditUserSysNo = new SqlParameter("@ManagerAuditUserSysNo", SqlDbType.Int,4);
			SqlParameter paramManagerAuditTime = new SqlParameter("@ManagerAuditTime", SqlDbType.DateTime);
			SqlParameter paramOutUserSysNo = new SqlParameter("@OutUserSysNo", SqlDbType.Int,4);
			SqlParameter paramOutTime = new SqlParameter("@OutTime", SqlDbType.DateTime);
			SqlParameter paramMemo = new SqlParameter("@Memo", SqlDbType.NVarChar,1000);
			SqlParameter paramNote = new SqlParameter("@Note", SqlDbType.NVarChar,1000);
			SqlParameter paramInvoiceNote = new SqlParameter("@InvoiceNote", SqlDbType.NVarChar,500);
			SqlParameter paramIsVAT = new SqlParameter("@IsVAT", SqlDbType.Int,4);
			SqlParameter paramIsPrintPackageCover = new SqlParameter("@IsPrintPackageCover", SqlDbType.Int,4);
			SqlParameter paramDeliveryMemo = new SqlParameter("@DeliveryMemo", SqlDbType.NVarChar,200);
			SqlParameter paramFinanceNote = new SqlParameter("@FinanceNote", SqlDbType.NVarChar,500);
			SqlParameter paramInvoiceNo = new SqlParameter("@InvoiceNo", SqlDbType.NVarChar,20);
			SqlParameter paramIsLarge = new SqlParameter("@IsLarge", SqlDbType.Int,4);
			SqlParameter paramPositiveSOSysNo = new SqlParameter("@PositiveSOSysNo", SqlDbType.Int,4);
            SqlParameter paramIsMobilePhone = new SqlParameter("@IsMobilePhone", SqlDbType.Int, 4);
            SqlParameter paramPromotionCodeSysNo = new SqlParameter("@PromotionCodeSysNo", SqlDbType.Int, 4);

			if ( oParam.SysNo != AppConst.IntNull) 
				paramSysNo.Value = oParam.SysNo;
			else
				paramSysNo.Value = System.DBNull.Value;
			if ( oParam.SOID != AppConst.StringNull)
				paramSOID.Value = oParam.SOID;
			else
				paramSOID.Value = System.DBNull.Value;
			if ( oParam.Status != AppConst.IntNull)
				paramStatus.Value = oParam.Status;
			else
				paramStatus.Value = System.DBNull.Value;
			if ( oParam.CustomerSysNo != AppConst.IntNull)
				paramCustomerSysNo.Value = oParam.CustomerSysNo;
			else
				paramCustomerSysNo.Value = System.DBNull.Value;
			if ( oParam.StockSysNo != AppConst.IntNull)
				paramStockSysNo.Value = oParam.StockSysNo;
			else
				paramStockSysNo.Value = System.DBNull.Value;
			if ( oParam.OrderDate != AppConst.DateTimeNull)
				paramOrderDate.Value = oParam.OrderDate;
			else
				paramOrderDate.Value = System.DBNull.Value;
			if ( oParam.DeliveryDate != AppConst.DateTimeNull)
				paramDeliveryDate.Value = oParam.DeliveryDate;
			else
				paramDeliveryDate.Value = System.DBNull.Value;
			if ( oParam.SalesManSysNo != AppConst.IntNull)
				paramSalesManSysNo.Value = oParam.SalesManSysNo;
			else
				paramSalesManSysNo.Value = System.DBNull.Value;
			if ( oParam.IsWholeSale != AppConst.IntNull)
				paramIsWholeSale.Value = oParam.IsWholeSale;
			else
				paramIsWholeSale.Value = System.DBNull.Value;
			if ( oParam.IsPremium != AppConst.IntNull)
				paramIsPremium.Value = oParam.IsPremium;
			else
				paramIsPremium.Value = System.DBNull.Value;
			if ( oParam.PremiumAmt != AppConst.DecimalNull)
				paramPremiumAmt.Value = oParam.PremiumAmt;
			else
				paramPremiumAmt.Value = System.DBNull.Value;
			if ( oParam.ShipTypeSysNo != AppConst.IntNull)
				paramShipTypeSysNo.Value = oParam.ShipTypeSysNo;
			else
				paramShipTypeSysNo.Value = System.DBNull.Value;
			if ( oParam.ShipPrice != AppConst.DecimalNull)
				paramShipPrice.Value = oParam.ShipPrice;
			else
				paramShipPrice.Value = System.DBNull.Value;
			if ( oParam.PayTypeSysNo != AppConst.IntNull)
				paramPayTypeSysNo.Value = oParam.PayTypeSysNo;
			else
				paramPayTypeSysNo.Value = System.DBNull.Value;
			if ( oParam.PayPrice != AppConst.DecimalNull)
				paramPayPrice.Value = oParam.PayPrice;
			else
				paramPayPrice.Value = System.DBNull.Value;
			if ( oParam.SOAmt != AppConst.DecimalNull)
				paramSOAmt.Value = oParam.SOAmt;
			else
				paramSOAmt.Value = System.DBNull.Value;
			if ( oParam.DiscountAmt != AppConst.DecimalNull)
				paramDiscountAmt.Value = oParam.DiscountAmt;
			else
				paramDiscountAmt.Value = System.DBNull.Value;
			if ( oParam.PointAmt != AppConst.IntNull)
				paramPointAmt.Value = oParam.PointAmt;
			else
				paramPointAmt.Value = System.DBNull.Value;
			if ( oParam.CashPay != AppConst.DecimalNull)
				paramCashPay.Value = oParam.CashPay;
			else
				paramCashPay.Value = System.DBNull.Value;
			if ( oParam.PointPay != AppConst.IntNull)
				paramPointPay.Value = oParam.PointPay;
			else
				paramPointPay.Value = System.DBNull.Value;
			if ( oParam.ReceiveAreaSysNo != AppConst.IntNull)
				paramReceiveAreaSysNo.Value = oParam.ReceiveAreaSysNo;
			else
				paramReceiveAreaSysNo.Value = System.DBNull.Value;
			if ( oParam.ReceiveContact != AppConst.StringNull)
				paramReceiveContact.Value = oParam.ReceiveContact;
			else
				paramReceiveContact.Value = System.DBNull.Value;
			if ( oParam.ReceiveName != AppConst.StringNull)
				paramReceiveName.Value = oParam.ReceiveName;
			else
				paramReceiveName.Value = System.DBNull.Value;
			if ( oParam.ReceivePhone != AppConst.StringNull)
				paramReceivePhone.Value = oParam.ReceivePhone;
			else
				paramReceivePhone.Value = System.DBNull.Value;
			if ( oParam.ReceiveCellPhone != AppConst.StringNull)
				paramReceiveCellPhone.Value = oParam.ReceiveCellPhone;
			else
				paramReceiveCellPhone.Value = System.DBNull.Value;
			if ( oParam.ReceiveAddress != AppConst.StringNull)
				paramReceiveAddress.Value = oParam.ReceiveAddress;
			else
				paramReceiveAddress.Value = System.DBNull.Value;
			if ( oParam.ReceiveZip != AppConst.StringNull)
				paramReceiveZip.Value = oParam.ReceiveZip;
			else
				paramReceiveZip.Value = System.DBNull.Value;
			if ( oParam.AllocatedManSysNo != AppConst.IntNull)
				paramAllocatedManSysNo.Value = oParam.AllocatedManSysNo;
			else
				paramAllocatedManSysNo.Value = System.DBNull.Value;
			if ( oParam.FreightUserSysNo != AppConst.IntNull)
				paramFreightUserSysNo.Value = oParam.FreightUserSysNo;
			else
				paramFreightUserSysNo.Value = System.DBNull.Value;
			if ( oParam.UpdateUserSysNo != AppConst.IntNull)
				paramUpdateUserSysNo.Value = oParam.UpdateUserSysNo;
			else
				paramUpdateUserSysNo.Value = System.DBNull.Value;
			if ( oParam.UpdateTime != AppConst.DateTimeNull)
				paramUpdateTime.Value = oParam.UpdateTime;
			else
				paramUpdateTime.Value = System.DBNull.Value;
			if ( oParam.AuditUserSysNo != AppConst.IntNull)
				paramAuditUserSysNo.Value = oParam.AuditUserSysNo;
			else
				paramAuditUserSysNo.Value = System.DBNull.Value;
			if ( oParam.AuditTime != AppConst.DateTimeNull)
				paramAuditTime.Value = oParam.AuditTime;
			else
				paramAuditTime.Value = System.DBNull.Value;
			if ( oParam.ManagerAuditUserSysNo != AppConst.IntNull)
				paramManagerAuditUserSysNo.Value = oParam.ManagerAuditUserSysNo;
			else
				paramManagerAuditUserSysNo.Value = System.DBNull.Value;
			if ( oParam.ManagerAuditTime != AppConst.DateTimeNull)
				paramManagerAuditTime.Value = oParam.ManagerAuditTime;
			else
				paramManagerAuditTime.Value = System.DBNull.Value;
			if ( oParam.OutUserSysNo != AppConst.IntNull)
				paramOutUserSysNo.Value = oParam.OutUserSysNo;
			else
				paramOutUserSysNo.Value = System.DBNull.Value;
			if ( oParam.OutTime != AppConst.DateTimeNull)
				paramOutTime.Value = oParam.OutTime;
			else
				paramOutTime.Value = System.DBNull.Value;
			if ( oParam.Memo != AppConst.StringNull)
				paramMemo.Value = oParam.Memo;
			else
				paramMemo.Value = System.DBNull.Value;
			if ( oParam.Note != AppConst.StringNull)
				paramNote.Value = oParam.Note;
			else
				paramNote.Value = System.DBNull.Value;
			if ( oParam.InvoiceNote != AppConst.StringNull)
				paramInvoiceNote.Value = oParam.InvoiceNote;
			else
				paramInvoiceNote.Value = System.DBNull.Value;
			if ( oParam.IsVAT != AppConst.IntNull)
				paramIsVAT.Value = oParam.IsVAT;
			else
				paramIsVAT.Value = System.DBNull.Value;
			if ( oParam.IsPrintPackageCover != AppConst.IntNull)
				paramIsPrintPackageCover.Value = oParam.IsPrintPackageCover;
			else
				paramIsPrintPackageCover.Value = System.DBNull.Value;
			if ( oParam.DeliveryMemo != AppConst.StringNull)
				paramDeliveryMemo.Value = oParam.DeliveryMemo;
			else
				paramDeliveryMemo.Value = System.DBNull.Value;

			if ( oParam.FinanceNote != AppConst.StringNull)
				paramFinanceNote.Value = oParam.FinanceNote;
			else
				paramFinanceNote.Value = System.DBNull.Value;

			if ( oParam.InvoiceNo != AppConst.StringNull)
				paramInvoiceNo.Value = oParam.InvoiceNo;
			else
				paramInvoiceNo.Value = System.DBNull.Value;

			if ( oParam.IsLarge != AppConst.IntNull)
				paramIsLarge.Value = oParam.IsLarge;
			else
				paramIsLarge.Value = System.DBNull.Value;

			if ( oParam.PositiveSOSysNo != AppConst.IntNull)
				paramPositiveSOSysNo.Value = oParam.PositiveSOSysNo;
			else
				paramPositiveSOSysNo.Value = System.DBNull.Value;

            if (oParam.IsMobilePhone != AppConst.IntNull)
                paramIsMobilePhone.Value = oParam.IsMobilePhone;
            else
                paramIsMobilePhone.Value = System.DBNull.Value;

            if (oParam.PromotionCodeSysNo != AppConst.IntNull)
                paramPromotionCodeSysNo.Value = oParam.PromotionCodeSysNo;
            else
                paramPromotionCodeSysNo.Value = System.DBNull.Value;

			cmd.Parameters.Add(paramSysNo);
			cmd.Parameters.Add(paramSOID);
			cmd.Parameters.Add(paramStatus);
			cmd.Parameters.Add(paramCustomerSysNo);
			cmd.Parameters.Add(paramStockSysNo);
			cmd.Parameters.Add(paramOrderDate);
			cmd.Parameters.Add(paramDeliveryDate);
			cmd.Parameters.Add(paramSalesManSysNo);
			cmd.Parameters.Add(paramIsWholeSale);
			cmd.Parameters.Add(paramIsPremium);
			cmd.Parameters.Add(paramPremiumAmt);
			cmd.Parameters.Add(paramShipTypeSysNo);
			cmd.Parameters.Add(paramShipPrice);
			cmd.Parameters.Add(paramPayTypeSysNo);
			cmd.Parameters.Add(paramPayPrice);
			cmd.Parameters.Add(paramSOAmt);
			cmd.Parameters.Add(paramDiscountAmt);
			cmd.Parameters.Add(paramPointAmt);
			cmd.Parameters.Add(paramCashPay);
			cmd.Parameters.Add(paramPointPay);
			cmd.Parameters.Add(paramReceiveAreaSysNo);
			cmd.Parameters.Add(paramReceiveContact);
			cmd.Parameters.Add(paramReceiveName);
			cmd.Parameters.Add(paramReceivePhone);
			cmd.Parameters.Add(paramReceiveCellPhone);
			cmd.Parameters.Add(paramReceiveAddress);
			cmd.Parameters.Add(paramReceiveZip);
			cmd.Parameters.Add(paramAllocatedManSysNo);
			cmd.Parameters.Add(paramFreightUserSysNo);
			cmd.Parameters.Add(paramUpdateUserSysNo);
			cmd.Parameters.Add(paramUpdateTime);
			cmd.Parameters.Add(paramAuditUserSysNo);
			cmd.Parameters.Add(paramAuditTime);
			cmd.Parameters.Add(paramManagerAuditUserSysNo);
			cmd.Parameters.Add(paramManagerAuditTime);
			cmd.Parameters.Add(paramOutUserSysNo);
			cmd.Parameters.Add(paramOutTime);
			cmd.Parameters.Add(paramMemo);
			cmd.Parameters.Add(paramNote);
			cmd.Parameters.Add(paramInvoiceNote);
			cmd.Parameters.Add(paramIsVAT);
			cmd.Parameters.Add(paramIsPrintPackageCover);
			cmd.Parameters.Add(paramDeliveryMemo);
			cmd.Parameters.Add(paramFinanceNote);
			cmd.Parameters.Add(paramInvoiceNo);
			cmd.Parameters.Add(paramIsLarge);
			cmd.Parameters.Add(paramPositiveSOSysNo);
            cmd.Parameters.Add(paramIsMobilePhone);
            cmd.Parameters.Add(paramPromotionCodeSysNo);

			return SqlHelper.ExecuteNonQuery(cmd);
		}

		public int InsertItem(SOItemInfo oParam)
		{
			string sql = @"INSERT INTO Ent_SO_Item
                            (
                            SOSysNo, ProductSysNo, Quantity, 
                            Weight, Price, Cost, Point, 
                            PointType, DiscountAmt, Warranty, ProductType, 
                            GiftSysNo, BriefName, OriginalPrice, PromotionDiscount
                            )
                            VALUES (
                            @SOSysNo, @ProductSysNo, @Quantity, 
                            @Weight, @Price, @Cost, @Point, 
                            @PointType, @DiscountAmt, @Warranty, @ProductType, 
                            @GiftSysNo, @BriefName, @OriginalPrice, @PromotionDiscount
                            )";
			
			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSOSysNo = new SqlParameter("@SOSysNo", SqlDbType.Int,4);
			SqlParameter paramProductSysNo = new SqlParameter("@ProductSysNo", SqlDbType.Int,4);
			SqlParameter paramQuantity = new SqlParameter("@Quantity", SqlDbType.Int,4);
			SqlParameter paramWeight = new SqlParameter("@Weight", SqlDbType.Int,4);
			SqlParameter paramPrice = new SqlParameter("@Price", SqlDbType.Decimal,9);
			SqlParameter paramCost = new SqlParameter("@Cost", SqlDbType.Decimal,9);
			SqlParameter paramPoint = new SqlParameter("@Point", SqlDbType.Int,4);
			SqlParameter paramPointType = new SqlParameter("@PointType", SqlDbType.Int,4);
			SqlParameter paramDiscountAmt = new SqlParameter("@DiscountAmt", SqlDbType.Decimal,9);
			SqlParameter paramWarranty = new SqlParameter("@Warranty", SqlDbType.NVarChar,500);
			SqlParameter paramProductType = new SqlParameter("@ProductType", SqlDbType.Int,4);
			SqlParameter paramGiftSysNo = new SqlParameter("@GiftSysNo", SqlDbType.Int,4);
            SqlParameter paramBriefName = new SqlParameter("@BriefName", SqlDbType.NVarChar, 100);
            SqlParameter paramOriginalPrice = new SqlParameter("@OriginalPrice", SqlDbType.Decimal, 9);
            SqlParameter paramPromotionDiscount = new SqlParameter("@PromotionDiscount", SqlDbType.Decimal, 9);

			if ( oParam.SOSysNo != AppConst.IntNull)
				paramSOSysNo.Value = oParam.SOSysNo;
			else
				paramSOSysNo.Value = System.DBNull.Value;
			if ( oParam.ProductSysNo != AppConst.IntNull)
				paramProductSysNo.Value = oParam.ProductSysNo;
			else
				paramProductSysNo.Value = System.DBNull.Value;
			if ( oParam.Quantity != AppConst.IntNull)
				paramQuantity.Value = oParam.Quantity;
			else
				paramQuantity.Value = System.DBNull.Value;
			if ( oParam.Weight != AppConst.IntNull)
				paramWeight.Value = oParam.Weight;
			else
				paramWeight.Value = System.DBNull.Value;
			if ( oParam.Price != AppConst.DecimalNull)
				paramPrice.Value = oParam.Price;
			else
				paramPrice.Value = System.DBNull.Value;
			if ( oParam.Cost != AppConst.DecimalNull)
				paramCost.Value = oParam.Cost;
			else
				paramCost.Value = System.DBNull.Value;
			if ( oParam.Point != AppConst.IntNull)
				paramPoint.Value = oParam.Point;
			else
				paramPoint.Value = System.DBNull.Value;
			if ( oParam.PointType != AppConst.IntNull)
				paramPointType.Value = oParam.PointType;
			else
				paramPointType.Value = System.DBNull.Value;
			if ( oParam.DiscountAmt != AppConst.DecimalNull)
				paramDiscountAmt.Value = oParam.DiscountAmt;
			else
				paramDiscountAmt.Value = System.DBNull.Value;
			if ( oParam.Warranty != AppConst.StringNull)
				paramWarranty.Value = oParam.Warranty;
			else
				paramWarranty.Value = System.DBNull.Value;
			if ( oParam.ProductType != AppConst.IntNull)
				paramProductType.Value = oParam.ProductType;
			else
				paramProductType.Value = System.DBNull.Value;
			if ( oParam.GiftSysNo != AppConst.IntNull)
				paramGiftSysNo.Value = oParam.GiftSysNo;
			else
				paramGiftSysNo.Value = System.DBNull.Value;

            if (oParam.BriefName != AppConst.StringNull)
                paramBriefName.Value = oParam.BriefName;
            else
                paramBriefName.Value = System.DBNull.Value;
            if (oParam.OriginalPrice != AppConst.DecimalNull)
                paramOriginalPrice.Value = oParam.OriginalPrice;
            else
                paramOriginalPrice.Value = System.DBNull.Value;
            if (oParam.PromotionDiscount != AppConst.DecimalNull)
                paramPromotionDiscount.Value = oParam.PromotionDiscount;
            else
                paramPromotionDiscount.Value = System.DBNull.Value;

			cmd.Parameters.Add(paramSOSysNo);
			cmd.Parameters.Add(paramProductSysNo);
			cmd.Parameters.Add(paramQuantity);
			cmd.Parameters.Add(paramWeight);
			cmd.Parameters.Add(paramPrice);
			cmd.Parameters.Add(paramCost);
			cmd.Parameters.Add(paramPoint);
			cmd.Parameters.Add(paramPointType);
			cmd.Parameters.Add(paramDiscountAmt);
			cmd.Parameters.Add(paramWarranty);
			cmd.Parameters.Add(paramProductType);
			cmd.Parameters.Add(paramGiftSysNo);
            cmd.Parameters.Add(paramBriefName);
            cmd.Parameters.Add(paramOriginalPrice);
            cmd.Parameters.Add(paramPromotionDiscount);

			return SqlHelper.ExecuteNonQuery(cmd);
		}

		public int UpdateSOMaster(SOInfo oParam)
		{			
			string sql = @"UPDATE Ent_SO_Master SET 
                           Status=@Status,DeliveryDate=@DeliveryDate, SalesManSysNo=@SalesManSysNo, 
                           IsWholeSale=@IsWholeSale, IsPremium=@IsPremium, 
                           PremiumAmt=@PremiumAmt, ShipTypeSysNo=@ShipTypeSysNo, 
                           ShipPrice=@ShipPrice, PayTypeSysNo=@PayTypeSysNo, 
                           PayPrice=@PayPrice, SOAmt=@SOAmt, 
                           DiscountAmt=@DiscountAmt, PointAmt=@PointAmt, 
                           CashPay=@CashPay, PointPay=@PointPay, ReceiveAreaSysNo=@ReceiveAreaSysNo,
                           ReceiveContact=@ReceiveContact, ReceiveName=@ReceiveName, 
                           ReceivePhone=@ReceivePhone, ReceiveCellPhone=@ReceiveCellPhone, ReceiveAddress=@ReceiveAddress, 
                           ReceiveZip=@ReceiveZip, AllocatedManSysNo=@AllocatedManSysNo, 
                           FreightUserSysNo=@FreightUserSysNo, UpdateUserSysNo=@UpdateUserSysNo, 
                           UpdateTime=@UpdateTime, AuditUserSysNo=@AuditUserSysNo, 
                           AuditTime=@AuditTime, ManagerAuditUserSysNo=@ManagerAuditUserSysNo, 
                           ManagerAuditTime=@ManagerAuditTime, OutUserSysNo=@OutUserSysNo, 
                           OutTime=@OutTime, Memo=@Memo, Note=@Note, InvoiceNote=@InvoiceNote, IsVAT=@IsVAT, 
                           IsPrintPackageCover=@IsPrintPackageCover, DeliveryMemo=@DeliveryMemo	,FinanceNote=@FinanceNote ,InvoiceNo=@InvoiceNo,
						   IsLarge=@IsLarge , PositiveSOSysNo=@PositiveSOSysNo , IsMobilePhone=@IsMobilePhone,
                           PromotionCodeSysNo=@PromotionCodeSysNo 
                           WHERE SysNo=@SysNo";
			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
			SqlParameter paramStatus = new SqlParameter("@Status", SqlDbType.Int,4);
			SqlParameter paramDeliveryDate = new SqlParameter("@DeliveryDate", SqlDbType.DateTime);
			SqlParameter paramSalesManSysNo = new SqlParameter("@SalesManSysNo", SqlDbType.Int,4);
			SqlParameter paramIsWholeSale = new SqlParameter("@IsWholeSale", SqlDbType.Int,4);
			SqlParameter paramIsPremium = new SqlParameter("@IsPremium", SqlDbType.Int,4);
			SqlParameter paramPremiumAmt = new SqlParameter("@PremiumAmt", SqlDbType.Decimal,9);
			SqlParameter paramShipTypeSysNo = new SqlParameter("@ShipTypeSysNo", SqlDbType.Int,4);
			SqlParameter paramShipPrice = new SqlParameter("@ShipPrice", SqlDbType.Decimal,9);
			SqlParameter paramPayTypeSysNo = new SqlParameter("@PayTypeSysNo", SqlDbType.Int,4);
			SqlParameter paramPayPrice = new SqlParameter("@PayPrice", SqlDbType.Decimal,9);
			SqlParameter paramSOAmt = new SqlParameter("@SOAmt", SqlDbType.Decimal,9);
			SqlParameter paramDiscountAmt = new SqlParameter("@DiscountAmt", SqlDbType.Decimal,9);
			SqlParameter paramPointAmt = new SqlParameter("@PointAmt", SqlDbType.Int,4);
			SqlParameter paramCashPay = new SqlParameter("@CashPay", SqlDbType.Decimal,9);
			SqlParameter paramPointPay = new SqlParameter("@PointPay", SqlDbType.Int,4);
			SqlParameter paramReceiveAreaSysNo = new SqlParameter("@ReceiveAreaSysNo", SqlDbType.Int,4);
			SqlParameter paramReceiveContact = new SqlParameter("@ReceiveContact", SqlDbType.NVarChar,20);
			SqlParameter paramReceiveName = new SqlParameter("@ReceiveName", SqlDbType.NVarChar,20);
			SqlParameter paramReceivePhone = new SqlParameter("@ReceivePhone", SqlDbType.NVarChar,100);
			SqlParameter paramReceiveCellPhone = new SqlParameter("@ReceiveCellPhone", SqlDbType.NVarChar,100);
			SqlParameter paramReceiveAddress = new SqlParameter("@ReceiveAddress", SqlDbType.NVarChar,200);
			SqlParameter paramReceiveZip = new SqlParameter("@ReceiveZip", SqlDbType.NVarChar,20);
			SqlParameter paramAllocatedManSysNo = new SqlParameter("@AllocatedManSysNo", SqlDbType.Int,4);
			SqlParameter paramFreightUserSysNo = new SqlParameter("@FreightUserSysNo", SqlDbType.Int,4);
			SqlParameter paramUpdateUserSysNo = new SqlParameter("@UpdateUserSysNo", SqlDbType.Int,4);
			SqlParameter paramUpdateTime = new SqlParameter("@UpdateTime", SqlDbType.DateTime);
			SqlParameter paramAuditUserSysNo = new SqlParameter("@AuditUserSysNo", SqlDbType.Int,4);
			SqlParameter paramAuditTime = new SqlParameter("@AuditTime", SqlDbType.DateTime);
			SqlParameter paramManagerAuditUserSysNo = new SqlParameter("@ManagerAuditUserSysNo", SqlDbType.Int,4);
			SqlParameter paramManagerAuditTime = new SqlParameter("@ManagerAuditTime", SqlDbType.DateTime);
			SqlParameter paramOutUserSysNo = new SqlParameter("@OutUserSysNo", SqlDbType.Int,4);
			SqlParameter paramOutTime = new SqlParameter("@OutTime", SqlDbType.DateTime);
			SqlParameter paramMemo = new SqlParameter("@Memo", SqlDbType.NVarChar,1000);
			SqlParameter paramNote = new SqlParameter("@Note", SqlDbType.NVarChar,1000);
			SqlParameter paramInvoiceNote = new SqlParameter("@InvoiceNote", SqlDbType.NVarChar,500);
			SqlParameter paramIsVAT = new SqlParameter("@IsVAT", SqlDbType.Int,4);
			SqlParameter paramIsPrintPackageCover = new SqlParameter("@IsPrintPackageCover", SqlDbType.Int,4);
			SqlParameter paramDeliveryMemo = new SqlParameter("@DeliveryMemo", SqlDbType.NVarChar,200);
			SqlParameter paramFinanceNote = new SqlParameter("@FinanceNote", SqlDbType.NVarChar,500);
			SqlParameter paramInvoiceNo = new SqlParameter("@InvoiceNo", SqlDbType.NVarChar,20);
			SqlParameter paramIsLarge = new SqlParameter("@IsLarge", SqlDbType.Int,4);
			SqlParameter paramPositiveSOSysNo = new SqlParameter("@PositiveSOSysNo", SqlDbType.Int,4);
            SqlParameter paramIsMobilePhone = new SqlParameter("@IsMobilePhone", SqlDbType.Int, 4);
            SqlParameter paramPromotionCodeSysNo = new SqlParameter("@PromotionCodeSysNo", SqlDbType.Int, 4);

			if ( oParam.SysNo != AppConst.IntNull)
				paramSysNo.Value = oParam.SysNo;
			else
				paramSysNo.Value = System.DBNull.Value;
			if ( oParam.Status != AppConst.IntNull)
				paramStatus.Value = oParam.Status;
			else
				paramStatus.Value = System.DBNull.Value;
			if ( oParam.DeliveryDate != AppConst.DateTimeNull)
				paramDeliveryDate.Value = oParam.DeliveryDate;
			else
				paramDeliveryDate.Value = System.DBNull.Value;
			if ( oParam.SalesManSysNo != AppConst.IntNull)
				paramSalesManSysNo.Value = oParam.SalesManSysNo;
			else
				paramSalesManSysNo.Value = System.DBNull.Value;
			if ( oParam.IsWholeSale != AppConst.IntNull)
				paramIsWholeSale.Value = oParam.IsWholeSale;
			else
				paramIsWholeSale.Value = System.DBNull.Value;
			if ( oParam.IsPremium != AppConst.IntNull)
				paramIsPremium.Value = oParam.IsPremium;
			else
				paramIsPremium.Value = System.DBNull.Value;
			if ( oParam.PremiumAmt != AppConst.DecimalNull)
				paramPremiumAmt.Value = oParam.PremiumAmt;
			else
				paramPremiumAmt.Value = System.DBNull.Value;
			if ( oParam.ShipTypeSysNo != AppConst.IntNull)
				paramShipTypeSysNo.Value = oParam.ShipTypeSysNo;
			else
				paramShipTypeSysNo.Value = System.DBNull.Value;
			if ( oParam.ShipPrice != AppConst.DecimalNull)
				paramShipPrice.Value = oParam.ShipPrice;
			else
				paramShipPrice.Value = System.DBNull.Value;
			if ( oParam.PayTypeSysNo != AppConst.IntNull)
				paramPayTypeSysNo.Value = oParam.PayTypeSysNo;
			else
				paramPayTypeSysNo.Value = System.DBNull.Value;
			if ( oParam.PayPrice != AppConst.DecimalNull)
				paramPayPrice.Value = oParam.PayPrice;
			else
				paramPayPrice.Value = System.DBNull.Value;
			if ( oParam.SOAmt != AppConst.DecimalNull)
				paramSOAmt.Value = oParam.SOAmt;
			else
				paramSOAmt.Value = System.DBNull.Value;
			if ( oParam.DiscountAmt != AppConst.DecimalNull)
				paramDiscountAmt.Value = oParam.DiscountAmt;
			else
				paramDiscountAmt.Value = System.DBNull.Value;
			if ( oParam.PointAmt != AppConst.IntNull)
				paramPointAmt.Value = oParam.PointAmt;
			else
				paramPointAmt.Value = System.DBNull.Value;
			if ( oParam.CashPay != AppConst.DecimalNull)
				paramCashPay.Value = oParam.CashPay;
			else
				paramCashPay.Value = System.DBNull.Value;
			if ( oParam.PointPay != AppConst.IntNull)
				paramPointPay.Value = oParam.PointPay;
			else
				paramPointPay.Value = System.DBNull.Value;
			if ( oParam.ReceiveAreaSysNo != AppConst.IntNull)
				paramReceiveAreaSysNo.Value = oParam.ReceiveAreaSysNo;
			else
				paramReceiveAreaSysNo.Value = System.DBNull.Value;
			if ( oParam.ReceiveContact != AppConst.StringNull)
				paramReceiveContact.Value = oParam.ReceiveContact;
			else
				paramReceiveContact.Value = System.DBNull.Value;
			if ( oParam.ReceiveName != AppConst.StringNull)
				paramReceiveName.Value = oParam.ReceiveName;
			else
				paramReceiveName.Value = System.DBNull.Value;
			if ( oParam.ReceivePhone != AppConst.StringNull)
				paramReceivePhone.Value = oParam.ReceivePhone;
			else
				paramReceivePhone.Value = System.DBNull.Value;
			if ( oParam.ReceiveCellPhone != AppConst.StringNull)
				paramReceiveCellPhone.Value = oParam.ReceiveCellPhone;
			else
				paramReceiveCellPhone.Value = System.DBNull.Value;
			if ( oParam.ReceiveAddress != AppConst.StringNull)
				paramReceiveAddress.Value = oParam.ReceiveAddress;
			else
				paramReceiveAddress.Value = System.DBNull.Value;
			if ( oParam.ReceiveZip != AppConst.StringNull)
				paramReceiveZip.Value = oParam.ReceiveZip;
			else
				paramReceiveZip.Value = System.DBNull.Value;
			if ( oParam.AllocatedManSysNo != AppConst.IntNull)
				paramAllocatedManSysNo.Value = oParam.AllocatedManSysNo;
			else
				paramAllocatedManSysNo.Value = System.DBNull.Value;
			if ( oParam.FreightUserSysNo != AppConst.IntNull)
				paramFreightUserSysNo.Value = oParam.FreightUserSysNo;
			else
				paramFreightUserSysNo.Value = System.DBNull.Value;
			if ( oParam.UpdateUserSysNo != AppConst.IntNull)
				paramUpdateUserSysNo.Value = oParam.UpdateUserSysNo;
			else
				paramUpdateUserSysNo.Value = System.DBNull.Value;
			if ( oParam.UpdateTime != AppConst.DateTimeNull)
				paramUpdateTime.Value = oParam.UpdateTime;
			else
				paramUpdateTime.Value = System.DBNull.Value;
			if ( oParam.AuditUserSysNo != AppConst.IntNull)
				paramAuditUserSysNo.Value = oParam.AuditUserSysNo;
			else
				paramAuditUserSysNo.Value = System.DBNull.Value;
			if ( oParam.AuditTime != AppConst.DateTimeNull)
				paramAuditTime.Value = oParam.AuditTime;
			else
				paramAuditTime.Value = System.DBNull.Value;
			if ( oParam.ManagerAuditUserSysNo != AppConst.IntNull)
				paramManagerAuditUserSysNo.Value = oParam.ManagerAuditUserSysNo;
			else
				paramManagerAuditUserSysNo.Value = System.DBNull.Value;
			if ( oParam.ManagerAuditTime != AppConst.DateTimeNull)
				paramManagerAuditTime.Value = oParam.ManagerAuditTime;
			else
				paramManagerAuditTime.Value = System.DBNull.Value;
			if ( oParam.OutUserSysNo != AppConst.IntNull)
				paramOutUserSysNo.Value = oParam.OutUserSysNo;
			else
				paramOutUserSysNo.Value = System.DBNull.Value;
			if ( oParam.OutTime != AppConst.DateTimeNull)
				paramOutTime.Value = oParam.OutTime;
			else
				paramOutTime.Value = System.DBNull.Value;
			if ( oParam.Memo != AppConst.StringNull)
				paramMemo.Value = oParam.Memo;
			else
				paramMemo.Value = System.DBNull.Value;
			if ( oParam.Note != AppConst.StringNull)
				paramNote.Value = oParam.Note;
			else
				paramNote.Value = System.DBNull.Value;
			if ( oParam.InvoiceNote != AppConst.StringNull)
				paramInvoiceNote.Value = oParam.InvoiceNote;
			else
				paramInvoiceNote.Value = System.DBNull.Value;
			if ( oParam.IsVAT != AppConst.IntNull)
				paramIsVAT.Value = oParam.IsVAT;
			else
				paramIsVAT.Value = System.DBNull.Value;
			if ( oParam.IsPrintPackageCover != AppConst.IntNull)
				paramIsPrintPackageCover.Value = oParam.IsPrintPackageCover;
			else
				paramIsPrintPackageCover.Value = System.DBNull.Value;
			if ( oParam.DeliveryMemo != AppConst.StringNull)
				paramDeliveryMemo.Value = oParam.DeliveryMemo;
			else
				paramDeliveryMemo.Value = System.DBNull.Value;

			if ( oParam.FinanceNote != AppConst.StringNull)
				paramFinanceNote.Value = oParam.FinanceNote;
			else
				paramFinanceNote.Value = System.DBNull.Value;

			if ( oParam.InvoiceNo != AppConst.StringNull)
				paramInvoiceNo.Value = oParam.InvoiceNo;
			else
				paramInvoiceNo.Value = System.DBNull.Value;

			if ( oParam.IsLarge != AppConst.IntNull)
				paramIsLarge.Value = oParam.IsLarge;
			else
				paramIsLarge.Value = System.DBNull.Value;

			if ( oParam.PositiveSOSysNo != AppConst.IntNull)
				paramPositiveSOSysNo.Value = oParam.PositiveSOSysNo;
			else
				paramPositiveSOSysNo.Value = System.DBNull.Value;

            if (oParam.IsMobilePhone != AppConst.IntNull)
                paramIsMobilePhone.Value = oParam.IsMobilePhone;
            else
                paramIsMobilePhone.Value = System.DBNull.Value;

            if (oParam.PromotionCodeSysNo != AppConst.IntNull)
                paramPromotionCodeSysNo.Value = oParam.PromotionCodeSysNo;
            else
                paramPromotionCodeSysNo.Value = System.DBNull.Value;

			cmd.Parameters.Add(paramSysNo);
			cmd.Parameters.Add(paramStatus);
			cmd.Parameters.Add(paramDeliveryDate);
			cmd.Parameters.Add(paramSalesManSysNo);
			cmd.Parameters.Add(paramIsWholeSale);
			cmd.Parameters.Add(paramIsPremium);
			cmd.Parameters.Add(paramPremiumAmt);
			cmd.Parameters.Add(paramShipTypeSysNo);
			cmd.Parameters.Add(paramShipPrice);
			cmd.Parameters.Add(paramPayTypeSysNo);
			cmd.Parameters.Add(paramPayPrice);
			cmd.Parameters.Add(paramSOAmt);
			cmd.Parameters.Add(paramDiscountAmt);
			cmd.Parameters.Add(paramPointAmt);
			cmd.Parameters.Add(paramCashPay);
			cmd.Parameters.Add(paramPointPay);
			cmd.Parameters.Add(paramReceiveAreaSysNo);
			cmd.Parameters.Add(paramReceiveContact);
			cmd.Parameters.Add(paramReceiveName);
			cmd.Parameters.Add(paramReceivePhone);
			cmd.Parameters.Add(paramReceiveCellPhone);
			cmd.Parameters.Add(paramReceiveAddress);
			cmd.Parameters.Add(paramReceiveZip);
			cmd.Parameters.Add(paramAllocatedManSysNo);
			cmd.Parameters.Add(paramFreightUserSysNo);
			cmd.Parameters.Add(paramUpdateUserSysNo);
			cmd.Parameters.Add(paramUpdateTime);
			cmd.Parameters.Add(paramAuditUserSysNo);
			cmd.Parameters.Add(paramAuditTime);
			cmd.Parameters.Add(paramManagerAuditUserSysNo);
			cmd.Parameters.Add(paramManagerAuditTime);
			cmd.Parameters.Add(paramOutUserSysNo);
			cmd.Parameters.Add(paramOutTime);
			cmd.Parameters.Add(paramMemo);
			cmd.Parameters.Add(paramNote);
			cmd.Parameters.Add(paramInvoiceNote);
			cmd.Parameters.Add(paramIsVAT);
			cmd.Parameters.Add(paramIsPrintPackageCover);
			cmd.Parameters.Add(paramDeliveryMemo);
			cmd.Parameters.Add(paramFinanceNote);
			cmd.Parameters.Add(paramInvoiceNo);
			cmd.Parameters.Add(paramIsLarge);
			cmd.Parameters.Add(paramPositiveSOSysNo);
            cmd.Parameters.Add(paramIsMobilePhone);
            cmd.Parameters.Add(paramPromotionCodeSysNo);
            
            return SqlHelper.ExecuteNonQuery(cmd);
		}

		public int UpdateSOMaster(Hashtable paramHash)
		{
			StringBuilder sb = new StringBuilder(200);
			sb.Append("UPDATE Ent_SO_Master SET ");

			if ( paramHash != null && paramHash.Count != 0 )
			{
				int index = 0;
				foreach(string key in paramHash.Keys)
				{
					object item = paramHash[key];
					if ( key.ToLower()=="sysno" )
						continue;

					if ( index != 0 )
						sb.Append(",");
					index++;

					
					if (item is int || item is decimal)
					{
						sb.Append(key).Append("=").Append(item.ToString());
					}
					else if (item is string)
					{
						sb.Append(key).Append(" = ").Append(Util.ToSqlString(item.ToString()));
					}
					else if (item is DateTime)
					{
						sb.Append(key).Append(" = cast(").Append( Util.ToSqlString(((DateTime)item).ToString(AppConst.DateFormatLong))).Append(" as DateTime)");
					}
					else if(item is System.DBNull)
					{
						sb.Append(key).Append("= null ");
					}
				}
			}

			sb.Append(" WHERE SysNo=").Append(paramHash["SysNo"]);

			return SqlHelper.ExecuteNonQuery(sb.ToString());
		}

		public int UpdateSOItem(SOItemInfo oParam)
		{
			string sql = @"UPDATE Ent_SO_Item SET 
                           Quantity=@Quantity, 
                           Weight=@Weight, Price=@Price, 
                           Cost=@Cost, Point=@Point, 
                           PointType=@PointType, DiscountAmt=@DiscountAmt, 
                           Warranty=@Warranty, ProductType=@ProductType, 
                           GiftSysNo=@GiftSysNo,
                           BriefName=@BriefName,
                           OriginalPrice=@OriginalPrice,
                           PromotionDiscount=@PromotionDiscount
                           WHERE SysNo=@SysNo";
			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4);
			SqlParameter paramQuantity = new SqlParameter("@Quantity", SqlDbType.Int,4);
			SqlParameter paramWeight = new SqlParameter("@Weight", SqlDbType.Int,4);
			SqlParameter paramPrice = new SqlParameter("@Price", SqlDbType.Decimal,9);
			SqlParameter paramCost = new SqlParameter("@Cost", SqlDbType.Decimal,9);
			SqlParameter paramPoint = new SqlParameter("@Point", SqlDbType.Int,4);
			SqlParameter paramPointType = new SqlParameter("@PointType", SqlDbType.Int,4);
			SqlParameter paramDiscountAmt = new SqlParameter("@DiscountAmt", SqlDbType.Decimal,9);
			SqlParameter paramWarranty = new SqlParameter("@Warranty", SqlDbType.NVarChar,500);
			SqlParameter paramProductType = new SqlParameter("@ProductType", SqlDbType.Int,4);
			SqlParameter paramGiftSysNo = new SqlParameter("@GiftSysNo", SqlDbType.Int,4);
            SqlParameter paramBriefName = new SqlParameter("@BriefName", SqlDbType.NVarChar, 100);
            SqlParameter paramOriginalPrice = new SqlParameter("@OriginalPrice", SqlDbType.Decimal, 9);
            SqlParameter paramPromotionDiscount = new SqlParameter("@PromotionDiscount", SqlDbType.Decimal, 9);

			if ( oParam.SysNo != AppConst.IntNull)
				paramSysNo.Value = oParam.SysNo;
			else
				paramSysNo.Value = System.DBNull.Value;
			if ( oParam.Quantity != AppConst.IntNull)
				paramQuantity.Value = oParam.Quantity;
			else
				paramQuantity.Value = System.DBNull.Value;
			if ( oParam.Weight != AppConst.IntNull)
				paramWeight.Value = oParam.Weight;
			else
				paramWeight.Value = System.DBNull.Value;
			if ( oParam.Price != AppConst.DecimalNull)
				paramPrice.Value = oParam.Price;
			else
				paramPrice.Value = System.DBNull.Value;
			if ( oParam.Cost != AppConst.DecimalNull)
				paramCost.Value = oParam.Cost;
			else
				paramCost.Value = System.DBNull.Value;
			if ( oParam.Point != AppConst.IntNull)
				paramPoint.Value = oParam.Point;
			else
				paramPoint.Value = System.DBNull.Value;
			if ( oParam.PointType != AppConst.IntNull)
				paramPointType.Value = oParam.PointType;
			else
				paramPointType.Value = System.DBNull.Value;
			if ( oParam.DiscountAmt != AppConst.DecimalNull)
				paramDiscountAmt.Value = oParam.DiscountAmt;
			else
				paramDiscountAmt.Value = System.DBNull.Value;
			if ( oParam.Warranty != AppConst.StringNull)
				paramWarranty.Value = oParam.Warranty;
			else
				paramWarranty.Value = System.DBNull.Value;
			if ( oParam.ProductType != AppConst.IntNull)
				paramProductType.Value = oParam.ProductType;
			else
				paramProductType.Value = System.DBNull.Value;
			if ( oParam.GiftSysNo != AppConst.IntNull)
				paramGiftSysNo.Value = oParam.GiftSysNo;
			else
				paramGiftSysNo.Value = System.DBNull.Value;

            if (oParam.BriefName != AppConst.StringNull)
                paramBriefName.Value = oParam.BriefName;
            else
                paramBriefName.Value = System.DBNull.Value;

            if (oParam.OriginalPrice != AppConst.DecimalNull)
                paramOriginalPrice.Value = oParam.OriginalPrice;
            else
                paramOriginalPrice.Value = System.DBNull.Value;

            if (oParam.PromotionDiscount != AppConst.DecimalNull)
                paramPromotionDiscount.Value = oParam.PromotionDiscount;
            else
                paramPromotionDiscount.Value = System.DBNull.Value;

			cmd.Parameters.Add(paramSysNo);
			cmd.Parameters.Add(paramQuantity);
			cmd.Parameters.Add(paramWeight);
			cmd.Parameters.Add(paramPrice);
			cmd.Parameters.Add(paramCost);
			cmd.Parameters.Add(paramPoint);
			cmd.Parameters.Add(paramPointType);
			cmd.Parameters.Add(paramDiscountAmt);
			cmd.Parameters.Add(paramWarranty);
			cmd.Parameters.Add(paramProductType);
			cmd.Parameters.Add(paramGiftSysNo);

            cmd.Parameters.Add(paramBriefName);
            cmd.Parameters.Add(paramOriginalPrice);
            cmd.Parameters.Add(paramPromotionDiscount);

			return SqlHelper.ExecuteNonQuery(cmd);
		}
        public int SetInvoiceNumber(int soSysNo, string invoiceList)
        {
            string sql = "update Ent_SO_Master set InvoiceNo = InvoiceNo + ' ' + " + Util.ToSqlString(invoiceList) + " where sysno=" + soSysNo;
            return SqlHelper.ExecuteNonQuery(sql);
        }
		public int UpdateSOItem(Hashtable paramHash)
		{
			StringBuilder sb = new StringBuilder(200);
			sb.Append("UPDATE Ent_SO_Item SET ");

			if ( paramHash != null && paramHash.Count != 0 )
			{
				int index = 0;
				foreach(string key in paramHash.Keys)
				{
					object item = paramHash[key];
					if ( key.ToLower()=="sysno" )
						continue;

					if ( index != 0 )
						sb.Append(",");
					index++;

					
					if (item is int || item is decimal)
					{
						sb.Append(key).Append("=").Append(item.ToString());
					}
					else if (item is string)
					{
						sb.Append(key).Append(" = ").Append(Util.ToSqlString(item.ToString()));
					}
					else if (item is DateTime)
					{
						sb.Append(key).Append(" = cast(").Append( Util.ToSqlString(((DateTime)item).ToString(AppConst.DateFormatLong))).Append(" as DateTime)");
					}
				}
			}

			sb.Append(" WHERE SysNo=").Append(paramHash["SysNo"]);

			return SqlHelper.ExecuteNonQuery(sb.ToString());
		}
		public int InsertSOSaleRule(SOSaleRuleInfo oParam)
		{
			string sql = @"INSERT INTO Ent_SO_SaleRule
                           (
                           SOSysNo, SaleRuleSysNo, SaleRuleName, 
                           Discount, Times, Note
                           )
                           VALUES (
                           @SOSysNo, @SaleRuleSysNo, @SaleRuleName, 
                           @Discount, @Times, @Note
                           )";

			SqlCommand cmd = new SqlCommand(sql);

			SqlParameter paramSOSysNo = new SqlParameter("@SOSysNo", SqlDbType.Int,4);
			SqlParameter paramSaleRuleSysNo = new SqlParameter("@SaleRuleSysNo", SqlDbType.Int,4);
			SqlParameter paramSaleRuleName = new SqlParameter("@SaleRuleName", SqlDbType.NVarChar,500);
			SqlParameter paramDiscount = new SqlParameter("@Discount", SqlDbType.Decimal,9);
			SqlParameter paramTimes = new SqlParameter("@Times", SqlDbType.Int,4);
			SqlParameter paramNote = new SqlParameter("@Note", SqlDbType.NVarChar,200);

			if ( oParam.SOSysNo != AppConst.IntNull)
				paramSOSysNo.Value = oParam.SOSysNo;
			else
				paramSOSysNo.Value = System.DBNull.Value;
			if ( oParam.SaleRuleSysNo != AppConst.IntNull)
				paramSaleRuleSysNo.Value = oParam.SaleRuleSysNo;
			else
				paramSaleRuleSysNo.Value = System.DBNull.Value;
			if ( oParam.SaleRuleName != AppConst.StringNull)
				paramSaleRuleName.Value = oParam.SaleRuleName;
			else
				paramSaleRuleName.Value = System.DBNull.Value;
			if ( oParam.Discount != AppConst.DecimalNull)
				paramDiscount.Value = oParam.Discount;
			else
				paramDiscount.Value = System.DBNull.Value;
			if ( oParam.Times != AppConst.IntNull)
				paramTimes.Value = oParam.Times;
			else
				paramTimes.Value = System.DBNull.Value;
			if ( oParam.Note != AppConst.StringNull)
				paramNote.Value = oParam.Note;
			else
				paramNote.Value = System.DBNull.Value;

			cmd.Parameters.Add(paramSOSysNo);
			cmd.Parameters.Add(paramSaleRuleSysNo);
			cmd.Parameters.Add(paramSaleRuleName);
			cmd.Parameters.Add(paramDiscount);
			cmd.Parameters.Add(paramTimes);
			cmd.Parameters.Add(paramNote);

			return SqlHelper.ExecuteNonQuery(cmd);
		}
		public int DeleteSOSaleRule(int soSysNo)
		{
			string sql = @"Delete from Ent_SO_SaleRule where SOSysNo = @SOSysNo";
			SqlCommand cmd = new SqlCommand(sql);
			SqlParameter paramSOSysNo = new SqlParameter("@SOSysNo", SqlDbType.Int,4);
			if ( soSysNo!= AppConst.IntNull)
				paramSOSysNo.Value = soSysNo;
			else
				paramSOSysNo.Value = System.DBNull.Value;
			cmd.Parameters.Add(paramSOSysNo);
			return SqlHelper.ExecuteNonQuery(cmd);			
		}
		public int DeleteSOItem(SOItemInfo itemInfo)
		{
			string sql = @"Delete from Ent_SO_Item where productsysno = @ProductSysNo and sosysno=@SOSysNo";
			SqlCommand cmd = new SqlCommand(sql);
			SqlParameter paramProductSysNo = new SqlParameter("@ProductSysNo", SqlDbType.Int,4);
			SqlParameter paramSOSysNo = new SqlParameter("@SOSysNo", SqlDbType.Int,4);
			if ( itemInfo.ProductSysNo!=AppConst.IntNull)
				paramProductSysNo.Value = itemInfo.ProductSysNo;
			else
				paramProductSysNo.Value = System.DBNull.Value;
			if ( itemInfo.SOSysNo!=AppConst.IntNull)
				paramSOSysNo.Value = itemInfo.SOSysNo;
			else 
				paramSOSysNo.Value = System.DBNull.Value;
			cmd.Parameters.Add(paramProductSysNo);
			cmd.Parameters.Add(paramSOSysNo);

			return SqlHelper.ExecuteNonQuery(cmd);
		}
	}
}
